<%@ page pageEncoding="UTF-8"%>
<%@ include file="/common/validate.jsp"%>
<%@ include file="function.jsp"%>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>编辑用户</title>
    <link  href="../../hos_manage/images/favicon.ico?cache=<%=Math.random()%>" rel="shortcut icon" type="image/x-icon">
    <link rel="stylesheet" href="../css/public.css?cache=<%=Math.random()%>">
    <link rel="stylesheet" href="../css/messages_doctor_mes.css?cache=<%=Math.random()%>">
    <link rel="stylesheet" href="../css/sweetalert.css?cache=<%=Math.random()%>" >
    <link rel="stylesheet" href="../css/pageCode.css?cache=<%=Math.random()%>" />

    <script src="../js/jquery-1.9.1.min.js"></script>
    <style>
        .role_name {
            height: auto;
        }
        .select_role {
            margin-top: 0;
            height: 40px;
        }
    </style>
</head>
<body>
    <%@ include file="../header.jsp"%>
    <!--内容-->
    <div class="containerone" id="edit_user">
    <%@ include file="../left_menu.jsp"%>
        <!--右边内容-->
        <div class="right_cont">
        <!--右边导航下面内容-->
            <div>
                <div class="message_hos_news_container">
                    <div class="department_top">
                        <div class="department_top_left department_top_top">
                        <span>
                          <p class="padding-right-min" v-html="title"></p>
                        </span>
                        </div>
                        <div class="department_top_right ui_line_height">
                          <a href="user.jsp" >
                              <span class="add_btn doctor_add_btn " id='doctor_add_btn'>返回</span>
                          </a>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                    <div class="role_box">
                        <div class="role_name">
                            <span>登录名:　</span>
                            <div class="ui_dark" v-html="user_name"></div>
                            <div class="test_tip"></div>
                        </div>
                        <div class="role_name">
                            <span>姓　名:　</span>
                            <input type="text" style="font-size:16px" v-model="form.name" @input="vali('name')" @compositionstart="vali('name')" @compositionend="vali('name')"/>
                            <div class="test_tip" v-html="formVali.name"/>
                        </div>
                        <div class="role_name">
                            <span>所属角色:</span>
                            <div class="select_role_box">
                            <select class="select_role" v-model="roleBelong">
                                <option v-for="item in roles" v-bind:value="{role_id: item.id}" v-html="item.name"></option>
                            </select>

                            </div>
                        </div>
                        <div class="role_sure" @click="submit()">确定</div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script src="/js/sweetalert-dev.js"></script>
    <script src="/js/vali.js"></script>
    <script type="text/javascript">
        new Vue({
            el: "#edit_user",
            data: {
                title: "编辑用户",
                roleBelong: {},
                user_name: "",
                user: {},
                roles: [],
                form: {
                    name: "",
                },
                formTag: {
                    name: true,
                },
                formVali: {
                    name: "",
                }
            },
            computed: {
                valiResultPass: function() {
                    for (var i in this.formVali) {
                        if (!this.formTag[i]) {
                            return false;
                        }
                    }
                    return true;
                }
            },
            methods: {
                submit: function() {
                    if (!this.valiResultPass) {
                        return;
                    }
                    $.ajax({
                        type: 'POST',
                        url: "edit_user.jsp",
                        data: hasHospitalPower.parms({
                            act: "update_user",
                            name: this.form.name,
                            user_id: this.user.id,
                            role_id: this.roleBelong.role_id + "",
                        }),
                        success: function(res) {
                            res = JSON.parse(res);
                            if (res.errcode == 0) {
                                swal({
                                    title: "编辑完成",
                                }, function() {
                                    locationHerf("user");
                                });
                            } else {
                                swal(res.errmsg);
                            }
                        },
                    });
                },
                vali: function(key) {
                    var text = validateModule.done(this.form, key);
                    if (text != "") {
                        this.formTag[key] = false;
                    } else {
                        this.formTag[key] = true;
                    }
                    this.formVali[key] = text;
                },
            },
            ready: function() {
                if (hasHospitalPower.power()) {
                    this.title += "-" + hasHospitalPower.nowHospital.name;
                }
                var editUserParms = getHrefParms("edit_user");
                var role = editUserParms.role;
                this.user = editUserParms.user;
                this.user_name = editUserParms.user.user_name;
                this.form.name = editUserParms.user.name;
                validateModule.addValidate("name", "name");
                $.ajax({
                    type: 'POST',
                    url: "edit_user.jsp",
                    data: hasHospitalPower.parms({
                        act: "roles",
                    }),
                    success: function(res) {
                        res = JSON.parse(res);
                        if (res.errcode == 0) {
                            this.roles = res.data;
                            this.roleBelong = {
                                role_id: role.id
                            }
                        } else {
                            swal(res.errmsg);
                        }
                    }.bind(this),
                });
            }
        });
    </script>
</body>
</html>
